/* GUI CONVERTED from gppiapm1.p (converter v1.75) Sun Aug 13 18:33:29 2000 */
/* gppiapm1.p - APM PRICE LIST SELECTION SUBPROGRAM                     */
/* Copyright 1986-2002 QAD Inc., Carpinteria, CA, USA.                  */
/* All rights reserved worldwide.  This is an unpublished work.         */
/* REVISION: 9.0       CREATED: 11/24/98         BY: *M017* Luke Pokic  */
/*V8:ConvertMode=Maintenance                                            */
/*M02W*/ /*V8:RunMode=Character,Windows                                 */
/* REVISION: 9.0      LAST MODIFIED: 12/22/98   BY: *M02W* Luke Pokic   */
/* REVISION: 9.0      LAST MODIFIED: 03/13/99   BY: *M0BD* Alfred Tan   */
/* REVISION: 9.0      LAST MODIFIED: 10/11/99   BY: *M0FS* Paul Coote   */
/* REVISION: 9.1      LAST MODIFIED: 08/13/00   BY: *N0KS* myb          */
/* Revision: EB2 SP3 GUI   BY: Kaine Zhang      DATE: 11/06/03   *hk-s-026*  */




         /* THIS SUBPROGRAM WILL FIND ALL THE QUALIFYING PRICE LISTS FOR THE
            CUSTOMER AND ITEM ON A SALES QUOTE/ORDER LINE. THIS SUBPROGRAM
            WILL:
            - BE INVOKED WHEN APM IS IN USE
            - BE RUN BY MFG/PRO PROGRAMS LIKE SALES ORDER MAINTENANCE
            - SELECT PRICE LISTS BY APM DIVISION WHEN PRICING A SALES
              ORDER/QUOTE LINE FOR A CUSTOMER AND ITEM USED BY APM
            - SELECT STANDARD MFG/PRO PRICE LIST WHEN PRICING A SALES
              ORDER/QUOTE LINE FOR A CUSTOMER AND ITEM NOT USED BY APM
            INPUT PARAMETERS:
               I-PICS_TYPE         (CUST/SUPPLIER TYPE 9 FOR CUST/ANAL. CODE)
               I-PICS_CODE         (CUST/ANALYSIS CODE)
               I-PART_TYPE         (PART TYPE 6 FOR ITEM/ANAL. CODE)
               I-PART_CODE         (ITEM/ANALYSIS CODE)
               I-PRICE_PAR         (PARENT ITEM)
               I-PRICE_FEAT        (FEATURE)
               I-PRICE_OPT         (OPTION)
               I-SRCH_TYPE         (SEARCH TYPE
                                    1- LIST PRICE 2 - DISCOUNT AND OTHERS)
               I-CURRENCY          (TRANSACTION CURRENCY)
               I-PRICE_UM          (PRICING UNIT OF MEASURE)
               I-PRICE_DATE        (PRICING DATE)
               I-MATCH_PT_UM       (INDICATES WHETHER A PRICE LIST IS REQD.)
               I-PRICE_SITE        (SITE)
               I-PRICE_EXCH_RATE   (EXCHANGE RATE)
               I-PRICE_EXCH_RATE2  (EXCHANGE RATE 2)
               I-PRICE_NBR         (SO/QUOTE NUMBER)
               I-PRICE_LINE        (SO/QUOTE LINE)
               I-DIV               (APM DIVISION)

            OUTPUT PARAMETER:
               O-ERROR_FLAG - NON ZERO WHEN ERROR FOUND.

            NOTES:
            THE INPUT PARAMETER I-PRICE_NBR WILL BE SET TO NULLS WHEN
            CALLED BY PRICING WHAT-IF INQUIRY SOPIWIIQ.P. WHEN PROCESSING
            A SALES ORDER I-PRICE_NBR WILL CONTAIN THE SO NUMBER.
            WHEN PROCESSING A QUOTE I-PRICE_NBR WILL CONTAIN "QOD_DET"
            AS THE FIRST SEVEN CHARACTERS FOLLOWED BY THE QUOTE NUMBER.

         */

         {mfdeclre.i} /* GLOBAL VARIABLES DECLARATIONS */

         define input  parameter i-pics_type      like pi_cs_type   no-undo.
         define input  parameter i-pics_code      like pi_cs_code   no-undo.
         define input  parameter i-part_type      like pi_part_type no-undo.
         define input  parameter i-part_code      like pi_part_code no-undo.
         define input  parameter i-price_par      like pih_parent   no-undo.
         define input  parameter i-price_feat     like pih_feature  no-undo.
         define input  parameter i-price_opt      like pih_option   no-undo.
         define input  parameter i-srch_type      like pi_srch_type no-undo.
         define input  parameter i-currency       like pi_curr      no-undo.
         define input  parameter i-price_um       like pi_um        no-undo.
         define input  parameter i-price_date     like pi_start     no-undo.
         define input  parameter i-match_pt_um    as   logical      no-undo.
         define input  parameter i-price_site     like sod_site     no-undo.
         define input  parameter i-price_exch_rate like so_ex_rate  no-undo.
         define input  parameter i-price_exch_rate2 like so_ex_rate2 no-undo.
         define input  parameter i-price_nbr      like sod_nbr      no-undo.
         define input  parameter i-price_line     like sod_line     no-undo.
         define input  parameter i-div            like sod_div      no-undo.

         define output parameter o-error_flag     as integer        no-undo.


         define variable v_prig1     like sod_prig1                 no-undo.
         define variable v_prig2     like sod_prig2                 no-undo.
         define variable prod_profile     as character extent 9
                         format "x(16)"                             no-undo.
         define variable v_ptgrp_group    as character              no-undo.
/*M0FS*/ define variable v_pics_code      as character              no-undo.
         define variable error_flag  like mfc_logical               no-undo.
         define variable err_mess_no like msg_nbr                   no-undo.
         define variable o-record_found   like mfc_logical          no-undo.
         define variable apm-ex-sub       as   character            no-undo.

         define buffer b1_pigp_det for pigp_det.
         define buffer b2_pigp_det for pigp_det.

         define buffer b1_pig_mstr for pig_mstr.

         {pppivar.i} /* SHARED VARIABLES FOR PRICING LOGIC */

/*M0FS*/ /* Temp Table for Considered Price Lists */
/*M0FS*/ define temp-table wkcpl_wkfl no-undo
/*M0FS*/    field wkcpl_list_id as character
/*M0FS*/    index wkcpl_list_id is unique primary
/*M0FS*/ wkcpl_list_id ascending.

         /* READ APM CTL FILE AND FLAG ERR IF IT DOES NOT EXIST */
         for first apm_ctrl
            fields(apm_div apm_multi_div apm_prig1 apm_prig2 apm_plpri)
            no-lock: end.

         if not available apm_ctrl then do:
            {mfmsg.i 4511 4} /* PLEASE CREATE APM CONTROL FILE */
            pause.
            o-error_flag = 100.
            return.
         end. /* IF NOT AVAILABLE APM_CTRL */

         assign
            apm-ex-sub    = "if/":U   /* ASSIGN APM SUB DIRECTORY */
            v_prig1 = ""
            v_prig2 = ""
            first_pilist = yes. /*For use by gppibx03.p when processing*/
                                /* list prices.                        */

         /* IF APM PRICING GROUP1 IS IN USE RUN IFAPM021.P TO OBTAIN
            THE VALUE OF PRICING GROUP1 AND PRICING GROUP2 */

         if apm_ctrl.apm_prig1 = yes then do:
            {gprunex.i
               &module  = 'APM':U
               &subdir  = apm-ex-sub
               &program = 'ifapm021.p':U
               &params  = "(input 1,
                            input i-part_code,
                            input i-div,
                            input-output v_ptgrp_group,
                            input-output v_prig1,
                            input-output v_prig2,
                            input-output prod_profile[1],
                            input-output prod_profile[2],
                            input-output prod_profile[3],
                            input-output prod_profile[4],
                            input-output prod_profile[5],
                            input-output prod_profile[6],
                            input-output prod_profile[7],
                            input-output prod_profile[8],
                            input-output prod_profile[9],
                            output error_flag,
                            output err_mess_no)"}
             if error_flag and err_mess_no <> 0 then do:
                {mfmsg.i err_mess_no 4} /* ERROR RETURNED BY IFAPM021.P */
                pause.
                o-error_flag = 99.
                return.
             end.  /* IF ERROR_FLAG AND ERR_MESS_NO <> 0 */
         end. /* IF APM_CTRL.APM_PRIG1 = YES */

         /* INITIALIZE SALES ORDER OR SALES QUOTES */
         if substring(i-price_nbr, 1, 7) = "qod_det" then do:
            for first qod_det
            fields (qod_nbr qod_line qod_prig1 qod_prig2)
               exclusive-lock
               where qod_nbr  = RIGHT-TRIM(substring(i-price_nbr,8,8))
               and   qod_line = i-price_line:
            end.
            qod_prig1 = if apm_ctrl.apm_prig1 then v_prig1 else "".
            qod_prig2 = if apm_ctrl.apm_prig2 then v_prig2 else "".
            for first qod_det
            fields (qod_nbr qod_line qod_prig1 qod_prig2) no-lock
               where qod_nbr  = RIGHT-TRIM(substring(i-price_nbr,8,8))
               and   qod_line = i-price_line:
            end.

         end. /* IF SUBSTRING(I-PRICE_NBR, 1, 7) = "QOD_DET" */
         else /* Sales Order */
            if substring(i-price_nbr, 1, 7) <> "qod_det" and
               substring(i-price_nbr, 1, 7) <> "" then do:
               for first sod_det
               fields (sod_nbr sod_line sod_prig1 sod_prig2)
                  exclusive-lock
                  where sod_nbr  = i-price_nbr
                  and   sod_line = i-price_line:
               end.
               sod_prig1 = if apm_ctrl.apm_prig1 then v_prig1 else "".
               sod_prig2 = if apm_ctrl.apm_prig2 then v_prig2 else "".
               for first sod_det
               fields (sod_nbr sod_line sod_prig1 sod_prig2) no-lock
                  where sod_nbr  = i-price_nbr
                  and   sod_line = i-price_line:
               end.
            end. /* IF SUBSTRING(I-PRICE_NBR, 1, 7) <> "QOD_DET" */

         /* FIND PRICE LIST GROUPS THE ITEM AND ITS ASSOCIATED
            PRICING GROUPS BELONG TO */
         o-error_flag = 0.
         run find_pl_group in THIS-PROCEDURE
            (output o-error_flag).

         return. /* RETURN TO CALLING PROGRAM */


         PROCEDURE find_pl_group:
         /*-----------------------------------------------------------------
           Purpose:    FINDS ALL THE PRICE LIST GROUPS THAT AN ITEM
                       AND ITS ASSOCIATED APM PRICING GROUPS BELONG TO
                       IN THE SELECTED APM DIVISION. IT ALSO SEARCHES FOR
                       EXCLUSION RECORDS. EG. A PRICE LIST GROUP COULD
                       INCLUDE ALL ITEMS EXCEPT ITEM A AND ITEM B.
           Parameters: OUTPUT O-ERROR_FLAG (SET TO NON-ZERO IF ERROR FOUND)
           Notes:
         -----------------------------------------------------------------*/

            define output parameter o-error_flag as integer        no-undo.

            /* FIND PRICE LIST GROUPS THAT THE ITEM BELONGS TO
               PIGP_PROD_TYPE = 1 INDICATES ITEM
               PIGP_AMT_TYPE = 1 INDICATES LIST PRICE */

            for each pigp_det
               where pigp_div = i-div
               and   pigp_prod_type = 1
               and   pigp_prod_ref  = i-part_code
               and   pigp_srch_type = i-srch_type
               and   (pigp_start   <= i-price_date or
                      pigp_start    = ?)
               and   (pigp_expire  >= i-price_date or
                      pigp_expire   = ?)
               and    pigp_include  = yes no-lock:

               run cust_price_list_check in THIS-PROCEDURE
                  (input  pigp_code,
                   input  pigp_amt_type,
                   input  i-part_code,
                   output o-error_flag).
               if o-error_flag > 0 then
                  return.
            end.  /* FOR EACH PIGP_DET  */
            /* FIND THE PRICE LIST GROUPS THAT APM PRICING GROUP2
               BELONGS TO. IF A RECORD IS FOUND, CHECK WHETHER THE ITEM
               IS EXCLUDED. */
            if v_prig2 <> "" then do:
               prig2_loop:
               /* PIGP_PROD_TYPE = 2 INDICATES PRICING GROUP 2
                  PIGP_AMT_TYPE = 1 INDICATES LIST PRICE */
               for each b1_pigp_det
                  where b1_pigp_det.pigp_div       = i-div
                  and   b1_pigp_det.pigp_prod_type = 2
                  and   b1_pigp_det.pigp_prod_ref  = v_prig2
                  and   b1_pigp_det.pigp_srch_type = i-srch_type
                  and   (b1_pigp_det.pigp_start   <= i-price_date or
                         b1_pigp_det.pigp_start    = ?)
                  and   (b1_pigp_det.pigp_expire  >= i-price_date or
                         b1_pigp_det.pigp_expire   = ?)
                  and   b1_pigp_det.pigp_include   = yes  no-lock:
                  /* IF PIGP_DET IS FOUND, CHECK WHETHER THIS ITEM IS
                     EXCLUDED FROM THIS PRICE LIST GROUP              */
                  run validate_item_prig in THIS-PROCEDURE
                     (input b1_pigp_det.pigp_code,
                      input 1,
                      input i-part_code,
                      input b1_pigp_det.pigp_amt_type,
                      input no,
                      output o-record_found).
                  if o-record_found then
                     next prig2_loop.
                  run cust_price_list_check in THIS-PROCEDURE
                     (input  b1_pigp_det.pigp_code,
                      input  b1_pigp_det.pigp_amt_type,
                      input  v_prig2,
                      output o-error_flag).
                  if o-error_flag > 0 then
                     return.
               end. /* FOR EACH B1_PIGP_DET */
            end. /* IF V_PRIG2 <> "" */

            /* FIND THE PRICE LIST GROUPS THAT APM PRICING GROUP
               1 BELONGS TO. IF RECORD FOUND, CHECK WHETHER THE ITEM OR
               PRICING GROUP 2 IS EXCLUDED. */

            if v_prig1 <> "" then do:
               prig1_loop:
               /* PIGP_PROD_TYPE = 3 INDICATES PRICING GROUP 1
                  PIGP_AMT_TYPE = 1 INDICATES LIST PRICE */
               for each b1_pigp_det
                  where b1_pigp_det.pigp_div = i-div
                  and   b1_pigp_det.pigp_prod_type = 3
                  and   b1_pigp_det.pigp_prod_ref = v_prig1
                  and   b1_pigp_det.pigp_srch_type = i-srch_type
                  and   (b1_pigp_det.pigp_start   <= i-price_date or
                         b1_pigp_det.pigp_start    = ?)
                  and   (b1_pigp_det.pigp_expire  >= i-price_date or
                         b1_pigp_det.pigp_expire   = ?)
                  and   b1_pigp_det.pigp_include   = yes no-lock:
                  /* IF PIGP_DET IS FOUND, CHECK WHETHER THIS ITEM IS
                     EXCLUDED FROM THIS PRICE LIST GROUP              */
                  run validate_item_prig in THIS-PROCEDURE
                     (input b1_pigp_det.pigp_code,
                      input 1,
                      input i-part_code,
                      input b1_pigp_det.pigp_amt_type,
                      input no,
                      output o-record_found).
                  if o-record_found then
                     next prig1_loop.
                  /* CHECK WHETHER PRICING GROUP 2 IS EXCLUDED FROM THIS
                      PRICE LIST GROUP                                    */
                  if v_prig2 <> "" then do:
                     run validate_item_prig in THIS-PROCEDURE
                        (input b1_pigp_det.pigp_code,
                         input 2,
                         input v_prig2,
                         input b1_pigp_det.pigp_amt_type,
                         input no,
                         output o-record_found).
                     if o-record_found then
                        next prig1_loop.
                  end. /* IF V_PRIG2 <> "" */
                  run cust_price_list_check in THIS-PROCEDURE
                     (input  b1_pigp_det.pigp_code,
                      input  b1_pigp_det.pigp_amt_type,
                      input  v_prig1,
                      output o-error_flag).
                  if o-error_flag > 0 then
                     return.
               end. /* FOR EACH B1_PIGP_DET */
            end. /* IF V_PRIG1 <> "" */

            /* FIND THE PRICE LIST GROUPS THAT APPLY TO ALL ITEMS.
               IF A RECORD IS FOUND, CHECK WHETHER THE ITEM OR PRICING
               GROUP1 OR PRICING GROUP2 IS EXCLUDED.                    */

            all_items_loop:
            for each pig_mstr
               where pig_div       = i-div
               and   pig_all_items = yes
               and   pig_srch_type = i-srch_type
               and   pig_curr      = i-currency
               and   (pig_start   <= i-price_date or
                      pig_start    = ?)
               and   (pig_expire  >= i-price_date or
                      pig_expire   = ?) no-lock:
               /* CHECK WHETHER ITEM IS EXCLUDED FROM THIS PRICE LIST GRP */
               run validate_item_prig in THIS-PROCEDURE
                  (input pig_code,
                   input 1,
                   input i-part_code,
                   input pig_amt_type,
                   input no,
                   output o-record_found).
               if o-record_found then
                  next all_items_loop.
               if v_prig2 <> "" then do:
                  /* CHECK WHETHER PRICING GROUP2 IS EXCLUDED FROM
                     THIS PRICE LIST GROUP                        */
                  run validate_item_prig in THIS-PROCEDURE
                     (input pig_code,
                      input 2,
                      input v_prig2,
                      input pig_amt_type,
                      input no,
                      output o-record_found).
                  if o-record_found then
                     next all_items_loop.
               end. /* IF V_PRIG2 <> "" */
               if v_prig1 <> "" then do:
                  /* CHECK WHETHER PRICING GROUP1 IS EXCLUDED FROM
                     THIS PRICING LIST GROUP                        */
                  run validate_item_prig in THIS-PROCEDURE
                     (input pig_code,
                      input 3,
                      input v_prig1,
                      input pig_amt_type,
                      input no,
                      output o-record_found).
                  if o-record_found then
                     next all_items_loop.
               end. /* IF V_PRIG1 <> "" */
               run cust_price_list_check in THIS-PROCEDURE
                  (input  pig_code,
                   input  pig_amt_type,
                   input  "qadall--+--+--+--+--+",
                   output o-error_flag).
               if o-error_flag > 0 then
                  return.
            end. /* FOR EACH PIG_MSTR */

            o-error_flag = 0. /* NO ERRORS FOUND */

         END PROCEDURE. /* PROCEDURE FIND_PL_GROUP */

         PROCEDURE validate_item_prig:
         /*-----------------------------------------------------------------
           Purpose:    VERIFIES WHETHER AN ITEM OR AN APM PRICING GROUP IS
                       INCLUDED OR EXCLUDED FROM A PRICE LIST GROUP.
           Parameters: INPUT  I-PIG_CODE  - PRICE LIST GRP CODE (I-PIG_CODE)
                              I-PROD_TYPE - PROD TYPE 1 = ITEM,
                                            2 = APM PRICING GRP2
                                            3 = APM PRICING GRP1 (I-PROD_TYPE)
                              I-PROD_REF  - ITEM OR PRICING GRP CODE
                                            (i-PROD_REF)
                              I-AMT_TYPE  - AMT TYPE  1 = LIST PRICE
                                            2-9 = DISCOUNTS (I-AMT_TYPE)
                              I-INCLUDE   - YES = PRICING GRP IS INCLUDED IN
                                                  PRICE LIST GRP
                       OUTPUT O-RECORD_FOUND - YES WHEN RECORD WAS FOUND
           Notes:
         -----------------------------------------------------------------*/
            define input parameter i-pig_code   like pigp_code      no-undo.
            define input parameter i-prod_type  like pigp_prod_type no-undo.
            define input parameter i-prod_ref   like pigp_prod_ref  no-undo.
            define input parameter i-amt_type   like pigp_amt_type  no-undo.
            define input parameter i-include    like pigp_include   no-undo.
            define output parameter o-record_found like mfc_logical no-undo.

            if can-find(first b2_pigp_det
               where b2_pigp_det.pigp_code      = i-pig_code
               and   b2_pigp_det.pigp_prod_type = i-prod_type
               and   b2_pigp_det.pigp_prod_ref  = i-prod_ref
               and   b2_pigp_det.pigp_amt_type  = i-amt_type
               and   (b2_pigp_det.pigp_start   <= i-price_date or
                      b2_pigp_det.pigp_start    = ?)
               and   (b2_pigp_det.pigp_expire  >= i-price_date or
                      b2_pigp_det.pigp_expire   = ?)
               and   b2_pigp_det.pigp_include   = i-include) then
               o-record_found = yes.
            else
               o-record_found = no.

         END PROCEDURE. /* PROCEDURE VALIDATE_ITEM_PRIG */


         PROCEDURE cust_price_list_check:
         /*-----------------------------------------------------------------
           Purpose:    VERIFIES WHETHER A CUSTOMER AND ITS ASSOCIATED APM
                       RELATIONSHIPS BELONG TO  A PRICE LIST GROUP. IT ALSO
                       SEARCHES EXCLUSION RECORDS (EG. A PRICE LIST GROUP
                       COULD INCLUDE ALL CUSTOMERS EXCEPT CUSTOMER A AND
                       CUSTOMER B.
           Parameters: INPUT  I-PIG_CODE   - PRICE LIST GRP CODE (I-PIG_CODE)
                              I-AMT_TYPE   - AMT TYPE  1 = LIST PRICE
                                             2-9 = DISCOUNTS
                              I-PART       - ITEM OR PRICING GRP CODE
                       OUTPUT O-ERROR_FLAG - RECORD FOUND
                                             (SET TO NON-ZERO VALUE IF ERROR)
           Notes:
         -----------------------------------------------------------------*/
            define input parameter i-pig_code   like pigp_code      no-undo.
            define input parameter i-amt_type   like pigp_amt_type  no-undo.
            define input parameter i-part       like pi_part_code   no-undo.
            define output parameter o-error_flag as  integer        no-undo.

            for first b1_pig_mstr
               fields (b1_pig_mstr.pig_code  b1_pig_mstr.pig_amt_type
                       b1_pig_mstr.pig_all_custs b1_pig_mstr.pig_list
                       b1_pig_mstr.pig_priority)
               where b1_pig_mstr.pig_code = i-pig_code
               and   b1_pig_mstr.pig_amt_type = i-amt_type no-lock:
            end.
            if not available b1_pig_mstr then do:
               {mfmsg03.i 4515 4 i-pig_code """" """"}
               /* APM PRICE LIST GROUP # NOT FOUND */
               pause.
               o-error_flag = 101.
               return.
            end. /* IF NOT AVAILABLE B1_PIG_MSTR */

            /* CHECK WHETHER THE PRICE LIST GROUP COVERS ALL CUSTOMERS
               IF IT DOES, CHECK TO SEE WHETHER THE CUSTOMER OR ANY
               ASSOCIATED CUSTOMER RELATIONSHIPS ARE EXCLUDED FROM THE
               PRICE LIST GROUP.                                       */
            if b1_pig_mstr.pig_all_custs = yes then do:
               /* CHECK WHETHER THE CUSTOMER IS EXCLUDED FROM PRICE LIST
                  GROUP */
/*M0FS*/ /* REMOVED THE FOLLOWING SECTION OF CODE */
/*
 *               run validate_cust_rel in THIS-PROCEDURE
 *                 (input i-pig_code,
 *                  input 1,
 *                  input i-pics_code,
 *                  input i-amt_type,
 *                  input no,
 *                  output o-record_found).
 *              if o-record_found then do:
 *                 o-error_flag = 0.
 *                 return. /* CUST EXCLUDED FROM PRICE LIST GRP */
 *              end.
 */
/*M0FS*/ /* END OF REMOVED SECTION */

               /* IF THE TRANSACTION IS A SALES QUOTE, CHECK ASSOCIATED
                  CUST REL ON THE SALES QUOTE LINE TO SEE WHETHER IT IS
                  EXCLUDED FROM THE PRICE LIST GROUP */
               if substring(i-price_nbr, 1, 7) = "qod_det" then do:
                  for each qodr_det
                  where qodr_nbr  = RIGHT-TRIM(substring(i-price_nbr,8,8))
                  and   qodr_line = i-price_line:
                    /* PRICING AND REBATES */
                     if can-find(first apmr_mstr
                        where apmr_seq = qodr_seq
                        and   apmr_pricing = 2
                        or    apmr_pricing = 3) then do:
                        /* CUSTOMER RELATIONSHIP */
                        run validate_cust_rel in THIS-PROCEDURE
                           (input i-pig_code,
                            input 2,
                            input qodr_group,
                            input i-amt_type,
                            input no,
                            output o-record_found).
                        if o-record_found then do:
                           o-error_flag = 0.
                           return. /* REL EXCLUDED FROM PRICE LIST GRP */
                        end. /* IF O-RECORD_FOUND  */
/*M0FS*/                assign v_pics_code = string(qodr_group,"x(10)")
/*M0FS*/                                   + i-pics_code.
/*M0FS*/                run validate_cust_rel in THIS-PROCEDURE
/*M0FS*/                   (input i-pig_code,
/*M0FS*/                    input 1,
/*M0FS*/                    input v_pics_code,
/*M0FS*/                    input i-amt_type,
/*M0FS*/                    input no,
/*M0FS*/                    output o-record_found).
/*M0FS*/                if o-record_found then do:
/*M0FS*/                   o-error_flag = 0.
/*M0FS*/                   return. /* CUST EXCLUDED FROM PRICE LIST GRP */
/*M0FS*/                end.
                     end. /* IF CAN-FIND APMR_MSTR */
                 end. /* FOR EACH QODR_DET */
               end. /* IF SUBSTRING(I-PRICE_NBR, 1, 7) = "QOD_DET" */
               /* IF THE TRANSACTION IS A SO OR RMA, CHECK ASSOCIATED
                  CUST REL ON THE ORDER LINE TO SEE WHETHER IT IS
                  EXCLUDED FROM THE PRICE LIST GROUP                  */
               if substring(i-price_nbr, 1, 7) <> "qod_det" and
                  substring(i-price_nbr, 1, 7) <> "" then do:
                  for each sodr_det
                  where sodr_nbr  = i-price_nbr
                  and   sodr_line = i-price_line:
                    /* PRICING AND REBATES */
                     if can-find(first apmr_mstr
                        where apmr_seq = sodr_seq
                        and   apmr_pricing = 2
                        or    apmr_pricing = 3) then do:
                        /* CUSTOMER RELATIONSHIP */
                        run validate_cust_rel in THIS-PROCEDURE
                           (input i-pig_code,
                            input 2,
                            input sodr_group,
                            input i-amt_type,
                            input no,
                            output o-record_found).
                        if o-record_found then do:
                           o-error_flag = 0.
                           return. /* REL EXCLUDED FROM PRICE LIST GRP */
                        end.
/*M0FS*/                assign v_pics_code = string(sodr_group,"x(10)")
/*M0FS*/                                   + i-pics_code.
/*M0FS*/                run validate_cust_rel in THIS-PROCEDURE
/*M0FS*/                   (input i-pig_code,
/*M0FS*/                    input 1,
/*M0FS*/                    input v_pics_code,
/*M0FS*/                    input i-amt_type,
/*M0FS*/                    input no,
/*M0FS*/                    output o-record_found).
/*M0FS*/                if o-record_found then do:
/*M0FS*/                   o-error_flag = 0.
/*M0FS*/                   return. /* CUST EXCLUDED FROM PRICE LIST GRP */
/*M0FS*/                end.
                     end. /* IF CAN-FIND APMR_MSTR */
                 end. /* FOR EACH SODR_DET */
               end. /* IF SUBSTRING(I-PRICE_NBR, 1, 7) <> "QOD_DET" */
               run store_price_lists in THIS-PROCEDURE
                  (input b1_pig_mstr.pig_list,
                   input i-part,
                   input b1_pig_mstr.pig_priority,
                   input i-amt_type,
                   output o-error_flag).
               return.
            end. /* IF B1_PIG_MSTR.PIG_ALL_CUSTS = YES */
            /* CHECK WHETHER THE CUSTOMER IS INCLUDED IN THE PRICE LIST
               GROUP */
/*M0FS*/ /* REMOVED THE FOLLOWING SECTION OF CODE */
/*
 *            run validate_cust_rel in THIS-PROCEDURE
 *              (input i-pig_code,
 *               input 1,
 *               input i-pics_code,
 *               input i-amt_type,
 *               input yes,
 *               output o-record_found).
 *           if o-record_found then do:
 *               /* CUSTOMER IS INCLUDED THE PRICE LIST GROUP */
 *              run store_price_lists in THIS-PROCEDURE
 *                 (input b1_pig_mstr.pig_list,
 *                  input i-part,
 *                  input b1_pig_mstr.pig_priority,
 *                  input i-amt_type,
 *                  output o-error_flag).
 *              if o-error_flag > 0  then
 *                 return.
 *           end.
 */
/*M0FS*/ /* END OF REMOVED SECTION */

            /* IF  TRANSACTION IS A SALES QUOTE, CHECK EACH ASSOCIATED
               CUST REL ON THE SALES QUOTE LINE TO SEE WHETHER IT IS
               INCLUDED IN THE PRICE LIST GROUP. IF RECORD FOUND, CHECK
               TO SEE WHETHER THE CUSTOMER IS EXCLUDED */
            if substring(i-price_nbr, 1, 7) = "qod_det" then do:
               for each qodr_det
               where qodr_nbr  = RIGHT-TRIM(substring(i-price_nbr,8,8))
               and   qodr_line = i-price_line:
                  /* PRICING AND REBATES */
                  if can-find(first apmr_mstr
                     where apmr_seq = qodr_seq
                     and   apmr_pricing = 2
                     or    apmr_pricing = 3) then do:
/*M0FS*/             /* CHECK CUSTOMER IS INCLUDED IN THE PRICE LIST
/*M0FS*/                GROUP */
/*M0FS*/             assign v_pics_code = string(qodr_group,"x(10)")
/*M0FS*/                                + i-pics_code.
/*M0FS*/             run validate_cust_rel in THIS-PROCEDURE
/*M0FS*/                (input i-pig_code,
/*M0FS*/                 input 1,
/*M0FS*/                 input v_pics_code,
/*M0FS*/                 input i-amt_type,
/*M0FS*/                 input yes,
/*M0FS*/                 output o-record_found).
/*M0FS*/             if o-record_found then do:
/*M0FS*/                /* CUSTOMER IS INCLUDED THE PRICE LIST GROUP */
/*M0FS*/                run store_price_lists in THIS-PROCEDURE
/*M0FS*/                   (input b1_pig_mstr.pig_list,
/*M0FS*/                    input i-part,
/*M0FS*/                    input b1_pig_mstr.pig_priority,
/*M0FS*/                    input i-amt_type,
/*M0FS*/                    output o-error_flag).
/*M0FS*/                if o-error_flag > 0  then
/*M0FS*/                   return.
/*M0FS*/                else next.
/*M0FS*/             end.
                     /* CUSTOMER RELATIONSHIP, LOOK FOR INCLUSION */
                     run validate_cust_rel in THIS-PROCEDURE
                        (input i-pig_code,
                         input 2,
                         input qodr_group,
                         input i-amt_type,
                         input yes,
                         output o-record_found).
                     if o-record_found then do:
                        /* REL IS INCLUDED IN THE PRICE LIST GRP. CHECK
                           WHETHER CUST IS EXCLUDED FROM PRICE LIST GROUP.
                           VALIDATE CUST REL FOR CUSTOMER AND EXCLUSION */
/*M0FS*/                assign v_pics_code = string(qodr_group,"x(10)")
/*M0FS*/                                   + i-pics_code.
                        run validate_cust_rel in THIS-PROCEDURE
                           (input i-pig_code,
                            input 1,
/*M0FS*                     input i-pics_code, */
/*M0FS*/                    input v_pics_code,
                            input i-amt_type,
                            input no,
                            output o-record_found).
                        /* CUSTOMER NOT EXCLUDED FROM PRICE LIST GROUP */
                        if not o-record_found then do:
                           run store_price_lists in THIS-PROCEDURE
                              (input b1_pig_mstr.pig_list,
                               input i-part,
                               input b1_pig_mstr.pig_priority,
                               input i-amt_type,
                               output o-error_flag).
                           if o-error_flag > 0  then
                              return.
                        end. /* IF NOT RECORD FOUND */
                     end. /* IF O-RECORD_FOUND */
                  end. /* IF CAN-FIND APMR_MSTR */
               end. /* FOR EACH QODR_DET */
            end. /* IF SUBSTRING(i-PRICE_NBR, 1, 7) = "QOD_DET" */

            /* IF  TRANSACTION IS A SO OR RMA, CHECK EACH ASSOCIATED
               CUST REL ON THE ORDER LINE TO SEE WHETHER IT IS
               INCLUDED IN THE PRICE LIST GROUP. IF RECORD FOUND, CHECK
               TO SEE WHETHER THE CUSTOMER IS EXCLUDED */
            if substring(i-price_nbr, 1, 7) <> "qod_det" and
               substring(i-price_nbr, 1, 7) <> "" then do:
               for each sodr_det
               where sodr_nbr  = i-price_nbr
               and   sodr_line  = i-price_line:
                 /* PRICING AND REBATES */
                  if can-find(first apmr_mstr
                  where apmr_seq = sodr_seq
                  and   apmr_pricing = 2
                  or    apmr_pricing = 3) then do:
/*M0FS*/             /* CHECK CUSTOMER IS INCLUDED IN THE PRICE LIST
/*M0FS*/                GROUP */
/*M0FS*/             assign v_pics_code = string(sodr_group,"x(10)")
/*M0FS*/                                + i-pics_code.
/*M0FS*/             run validate_cust_rel in THIS-PROCEDURE
/*M0FS*/                (input i-pig_code,
/*M0FS*/                 input 1,
/*M0FS*/                 input v_pics_code,
/*M0FS*/                 input i-amt_type,
/*M0FS*/                 input yes,
/*M0FS*/                 output o-record_found).
/*M0FS*/             if o-record_found then do:
/*M0FS*/                /* CUSTOMER IS INCLUDED THE PRICE LIST GROUP */
/*M0FS*/                run store_price_lists in THIS-PROCEDURE
/*M0FS*/                   (input b1_pig_mstr.pig_list,
/*M0FS*/                    input i-part,
/*M0FS*/                    input b1_pig_mstr.pig_priority,
/*M0FS*/                    input i-amt_type,
/*M0FS*/                    output o-error_flag).
/*M0FS*/                if o-error_flag > 0  then
/*M0FS*/                   return.
/*M0FS*/                else next.
/*M0FS*/             end.
                     /* CUSTOMER RELATIONSHIP, LOOK FOR INCLUSION */
                     run validate_cust_rel in THIS-PROCEDURE
                        (input i-pig_code,
                         input 2,
                         input sodr_group,
                         input i-amt_type,
                         input yes,
                         output o-record_found).
                     if o-record_found then do:
                     /* REL IS INCLUDED IN THE PRICE LIST GRP. CHECK
                        WHETHER CUST IS EXCLUDED FROM PRICE LIST GROUP */
                        /* CUSTOMER AND EXCLUSION */
/*M0FS*/                assign v_pics_code = string(sodr_group,"x(10)")
/*M0FS*/                                   + i-pics_code.
                        run validate_cust_rel in THIS-PROCEDURE
                           (input i-pig_code,
                            input 1,
/*M0FS*                     input i-pics_code, */
/*M0FS*/                    input v_pics_code,
                            input i-amt_type,
                            input no,
                            output o-record_found).
                        /* CUSTOMER NOT EXCLUDED FROM PRICE LIST GROUP */
                        if not o-record_found then do:
                           run store_price_lists in THIS-PROCEDURE
                              (input b1_pig_mstr.pig_list,
                               input i-part,
                               input b1_pig_mstr.pig_priority,
                               input i-amt_type,
                               output o-error_flag).
                           if o-error_flag > 0 then
                              return.
                        end. /* IF NOT O-RECORD_FOUND */
                     end. /* IF O-RECORD_FOUND */
                  end. /* IF CAN-FIND APMR_MSTR */
               end. /* FOR EACH SODR_DET */
            end. /* IF SUBSTRING(I-PRICE_NBR, 1, 7) <> "QOD_DET" */

         END PROCEDURE. /* PROCEDURE CUST_PRICE_LIST_CHECK */

         PROCEDURE validate_cust_rel:
         /*-----------------------------------------------------------------
           Purpose:    VERIFIES WHETHER A CUSTOMER OR AN ASSOCIATED APM
                       RELATIONSHIP IS INCLUDED OR EXCLUDED FROM A PRICE
                       LIST GROUP.
           Parameters: INPUT  I-MEM_TYPE  - 1 = CUSTOMER
                                            2 = CUSTOMER RELATIONSHIP
                                                (EG. CUST GROUP)
                              I-MEM_REF   - CUSTOMER OR CUSTOMER RELATIONSHIP
                                            CODE
                              I-INCLUDE   - WHEN YES, VERIFY WHETHER THE CUST
                                            OR RELATIONSHIP IS INCLUDED IN
                                            THE PRICE LIST GROUP
                       OUTPUT O-RECORD_FOUND - WHEN YES A RECORD WAS FOUND
                                               IN THE PRICE LIST GROUP
           Notes:
         -----------------------------------------------------------------*/
            define input parameter i-pig_code   like pigc_code      no-undo.
            define input parameter i-mem_type   like pigc_mem_type  no-undo.
            define input parameter i-mem_ref    like pigc_mem_ref   no-undo.
            define input parameter i-amt_type   like pigc_amt_type  no-undo.
            define input parameter i-include    like pigc_include   no-undo.
            define output parameter o-record_found like mfc_logical no-undo.

            if can-find(first pigc_det
               where pigc_code     = i-pig_code
               and   pigc_mem_type = i-mem_type
               and   pigc_mem_ref  = i-mem_ref
               and   pigc_amt_type = i-amt_type
               and   (pigc_start   <= i-price_date or
                      pigc_start    = ?)
               and   (pigc_expire  >= i-price_date or
                      pigc_expire   = ?)
               and   pigc_include  = i-include) then
               o-record_found = yes.
            else
               o-record_found = no.

         END PROCEDURE. /* PROCEDURE VALIDATE_CUST_REL */

         PROCEDURE store_price_lists:
         /*-----------------------------------------------------------------
           Purpose:    RUNS SUB-PROGRAM GPPIBX03.P TO STORE THE SELECTED
                       PRICE LIST IN THE PRICING WORK FILE (WKPI_WKFL).

           Parameters: INPUT  I-PIG_LIST  - PRICE LIST NAME
                              I-PART      - ITEM OR APM PRICING GROUP CODE
                              I-PIG_PRIORITY - PRICE LIST GROUP PRIORITY
                              I-AMT-TYPE  - AMOUNT TYPE
                       OUTPUT O-ERROR_FLAG   - SET TO NON-ZERO WHEN AN ERROR
                                               IS FOUND
           Notes:
         -----------------------------------------------------------------*/
            define input parameter i-pig_list   like pi_list        no-undo.
            define input parameter i-part       like pi_part_code   no-undo.
            define input parameter i-pig_priority like pig_priority no-undo.
            define input parameter i-amt_type   like pigc_amt_type  no-undo.
            define output parameter o-error_flag  as integer        no-undo.

            /* MATCH ON ITEM, UM AND CURRENCY */

            if i-match_pt_um = yes then do:
            	/*hk-s-026*  add "and pi_user1 = .... */
               for each pi_mstr
               where pi_list      = i-pig_list
               and   pi_cs_type   = i-pics_type
               and   pi_cs_code   = "APM"
               and   pi_part_type = i-part_type
               and   pi_part_code = i-part
               and   pi_curr      = i-currency
               and   pi_um        = i-price_um
               and   (pi_start   <= i-price_date or pi_start = ?)
               and   (pi_expire  >= i-price_date or pi_expire = ?)
               and   pi_user1 = i-price_site
               no-lock:
/*GUI*/ if global-beam-me-up then undo, leave.

/*M0FS*/          find first wkcpl_wkfl
/*M0FS*/               where wkcpl_list_id = pi_list_id
/*M0FS*/               no-lock no-error.
/*M0FS*/          if available wkcpl_wkfl then next.
                  if available pi_mstr then do:
                     {gprun.i ""gppibx03.p"" "(input pi_list_id,
                        input i-part_code,
                        input i-price_um,
                        input i-price_par,
                        input i-price_feat,
                        input i-price_opt,
                        input i-price_site,
                        input i-price_exch_rate,
                        input i-price_exch_rate2,
                        output o-error_flag)" }
/*GUI*/ if global-beam-me-up then undo, leave.

/*M0FS*/             create wkcpl_wkfl.
/*M0FS*/             assign wkcpl_list_id = pi_list_id.
                  end. /* IF AVAILABLE PI_MSTR */
               end.
/*GUI*/ if global-beam-me-up then undo, leave.
 /* FOR EACH PI_MSTR */
            end. /* IF I-MATCH_PT_UM = YES */
            else do:
               /*hk-s-026*  add "and pi_user1 = .... */
               for each pi_mstr
               where pi_list      = i-pig_list
               and   pi_cs_type   = i-pics_type
               and   pi_cs_code   = "APM"
               and   pi_part_type = i-part_type
               and   pi_part_code = i-part
               and   pi_curr      = i-currency
               and   (pi_start   <= i-price_date or pi_start = ?)
               and   (pi_expire  >= i-price_date or pi_expire = ?)
               and   pi_user1 = i-price_site
               no-lock:
/*GUI*/ if global-beam-me-up then undo, leave.

/*M0FS*/          find first wkcpl_wkfl
/*M0FS*/               where wkcpl_list_id = pi_list_id
/*M0FS*/               no-lock no-error.
/*M0FS*/          if available wkcpl_wkfl then next.
                  if available pi_mstr then do:
                     {gprun.i ""gppibx03.p"" "(input pi_list_id,
                        input i-part_code,
                        input i-price_um,
                        input i-price_par,
                        input i-price_feat,
                        input i-price_opt,
                        input i-price_site,
                        input i-price_exch_rate,
                        input i-price_exch_rate2,
                        output o-error_flag)" }
/*GUI*/ if global-beam-me-up then undo, leave.

/*M0FS*/             create wkcpl_wkfl.
/*M0FS*/             assign wkcpl_list_id = pi_list_id.
                  end. /* IF AVAILABLE PI_MSTR */
               end.
/*GUI*/ if global-beam-me-up then undo, leave.
 /* FOR EACH PI_MSTR */
            end. /* ELSE - IF I-MATCH_PT_UM = NO */
         END PROCEDURE. /* PROCEDURE STORE_PRICE_LISTS */
